// 角色对应的权限
const roleToRoute = {
  coustomer: [
    'product',
    'productList',
    'productAdd',
    'productEdit',
  ],
  admin: [
    'product',
    'productList',
    'productAdd',
    'productEdit',
    'category',
  ],
};
/**
 * 获取角色的动态路由
 * @param {String} role 角色
 * @param {Array} routes 动态路由
 * @returns
 */
export default function getMenuRoutes(role, routes) {
  if (!role) return [];
  const allows = roleToRoute[role];
  if (!allows) {
    window.$message.error('未知角色登录！！');
    return [];
  }
  const resultRoutes = routes.filter((r) => allows.includes(r.name));
  resultRoutes.forEach((route) => {
    const r = route;
    if (r.children) r.children = getMenuRoutes(role, r.children);
  });
  return resultRoutes;
}
